package com.mlnx.work.pojo.vo;

import com.mlnx.work.enums.ProjectStatusEnum;
import com.mlnx.work.utils.DateUtil;
import com.mlnx.work.utils.TagUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

@Data
@ApiModel("项目下任务列表返回参数类")
public class ProjectTaskListVO {
    @ApiModelProperty("任务ID")
    private Integer taskId;

    @ApiModelProperty("自动编号")
    private String itemNo;

    @ApiModelProperty("任务名称")
    private String taskName;

    @ApiModelProperty("任务描述")
    private String description;

    @ApiModelProperty("最初计划开始时间")
    private Long originStartTime;

    @ApiModelProperty("实际开始时间")
    private Long startTime;

    @ApiModelProperty("最初计划结束时间")
    private Long originEndTime;

    @ApiModelProperty("实际完成时间")
    private Long completedTime;

    @ApiModelProperty("任务状态")
    private ProjectStatusEnum status;

    @ApiModelProperty("逾期计划时间")
    private Long overdueTime;

    @ApiModelProperty("逾期比")
    private Float overdueRate;

    @ApiModelProperty("逾期次数")
    private Integer overdueTimes;

    @ApiModelProperty("交付成果")
    private String achievement;

    @ApiModelProperty("风险项")
    private String risk;

    @ApiModelProperty("标签")
    private String tags;

    @ApiModelProperty("里程碑")
    private Boolean milepost;

    @ApiModelProperty("工时")
    private Integer workHour;

    @ApiModelProperty("负责人")
    private String manager;

    public String getStatus() {
        if (ProjectStatusEnum.ING.equals(status))
            if (DateUtil.dateCompare(originEndTime, System.currentTimeMillis()) < 0)
                status = ProjectStatusEnum.OVERDUE;
            else if (!risk.trim().isEmpty())
                status = ProjectStatusEnum.RISK;

        return status.getStatus();
    }

    public Float getOverdueRate() {
        if (overdueTime == null)
            return 0f;

        float f1 = DateUtil.dayBetween(overdueTime, originStartTime) + 1;
        float f2 = DateUtil.dayBetween(originEndTime, originStartTime) + 1;
        return f1 / f2;
    }

    public List<String> getTags() {
        return TagUtil.getTags(tags);
    }
}
